package com.ch3cooh.servercachetest.app;

import java.util.concurrent.atomic.AtomicInteger;

public class TestThreadLocal {

    public static void main(String[] args) {

        ThreadLocal<Integer> threadLocal= new ThreadLocal<>();

        final AtomicInteger count = new AtomicInteger(1);

        for(int i = 10; i>0; --i){
           new Thread(()->{
               threadLocal.set(count.get());
               count.getAndIncrement();
               System.out.println(Thread.currentThread().getName() + " set: " + threadLocal.get() );
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               System.out.println(Thread.currentThread().getName() + " get: " + threadLocal.get() );
           }).start();
        }

    }


}
